package com.axonactive.yolo.service.internal;

import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import com.axonactive.yolo.exception.UserEmailNotFoundException;
import com.axonactive.yolo.exception.UserNotFoundException;
import com.axonactive.yolo.monitor.UnactivatedEmailCleaner;

public class QuartzJobUnactivatedEmailCleaner extends QuartzJobBean {

	private UnactivatedEmailCleaner unactivatedEmailCleaner;

	public void setUnactivatedEmailCleaner(
			UnactivatedEmailCleaner unactivatedEmailCleaner) {
		this.unactivatedEmailCleaner = unactivatedEmailCleaner;
	}

	protected void executeInternal(JobExecutionContext context)
			throws JobExecutionException {
		try {
			unactivatedEmailCleaner.run();
		} catch (UserEmailNotFoundException | UserNotFoundException e) {
			Logger.getLogger(QuartzJobUnactivatedEmailCleaner.class).error(
					"UserEmail or User not found", e);
		}
	}
}
